import com.sun.source.tree.Tree;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-08-21
 * 17:51
 */
public class Test {

//    public static void main(String[] args) {
//        Main main1=new Main();
//        Main.TreeNode root=main1.createTree("cf#g#ny#h#t##hpg##h#e##oebr####h##r##");
//        main1.order(root);
//    }
 }
 class Main {
    public static class TreeNode {
        Character val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(Character val) {
            this.val = val;
        }
        TreeNode(Character val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
      //  while (in.hasNextInt()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            TreeNode root = createTree(s);
            order(root);
     //   }
    }


    public static int i = 0;
    public static TreeNode createTree(String s) {
        TreeNode root = null;
        if (s.charAt(i) != '#') {
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = createTree(s);
            root.right = createTree(s);
        } else {
            i++;
        }
        return root;
    }
    public static   void order(TreeNode root) {
        if (root == null) {
            return;
        }
        order(root.left);
        System.out.print(root.val+" ");
        order(root.right);
    }
}